package com.cy.store.service.impl;

import com.cy.store.entity.Product;

import com.cy.store.mapper.ProductMapper;
import com.cy.store.service.IProductService;
import com.cy.store.service.ex.ProductNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    ProductMapper productMapper;

    /**
     * 展示热销商品
     */
    @Override
    public List<Product> findHotList() {
        List<Product> list = productMapper.findHotList();
        System.out.println("热销商品：");
        for(Product b: list){
            b.setPriority(null);
            b.setCreatedUser(null);
            b.setCreatedTime(null);
            b.setModifiedUser(null);
            b.setModifiedTime(null);

            System.out.println(b);
        }
        return list;
    }

    /**
     * 展示商品详细信息
     */
    @Override
    public Product findById(Integer id) {

        Product product = productMapper.findById(id);
        if(product == null){
            throw new ProductNotFoundException("没有发现商品详细信息");
        }

        product.setPriority(null);
        product.setCreatedUser(null);
        product.setCreatedTime(null);
        product.setModifiedUser(null);
        product.setModifiedTime(null);

        return product;
    }


}
